package com.coderman.daoclient.connections;

import com.coderman.daoclient.utils.JdbcUtils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by ${fanchunshuai} on 2017-7-27.
 *
 * @version: V1.0
 * @Desc:
 * @Copyright (c) 2017 58到家-版权所有
 */
public class SimpleDataSource implements ConnectionFactory{
    private Connection connection;
    private  DBConfig dbConfig ;

    public SimpleDataSource(DBConfig dbConfig){
        this.dbConfig = dbConfig;
    }

    @Override
    public Connection createConnection() throws SQLException {

        JdbcUtils.registerDriver(dbConfig.getJdbcDriver());
        // 3.获取数据库连接
        connection = DriverManager.getConnection(dbConfig.getUrl(), dbConfig.getUser(), dbConfig.getPassword());
        return  connection;
    }
}
